<?php 
	require 'connection.php';
	
	if(!isLogged())
	{
		header('location:login.php');
	}
	
?>

<html>
<head>
	<title>Traktori</title>
	<link type="text/css" href="style/index_css.css" rel="stylesheet"/>
</head>
<body>
<?php 
$query = "select traktor_id,img, concat(name,\" \",model) as Top_model from traktor";
$result = mysqli_query($db_connect, $query) or die(mysqli_error($db_connect));
?>
	<div>
		<h1 id="top">Traktori</h1>
	</div>
	<div id="left">
		<a href="add_traktors.php"><h2>Add</h2></a></br>
	</div>
	<div id="center">
	<?php 
	echo "<table border=\"2\">";
	echo "<tr><th>ID</th><th>image</th><th>model</th><th>Edit</th></tr>";
	if(mysqli_num_rows($result) > 0)
	{
		while($row = mysqli_fetch_assoc($result) )
		{
			if($row['traktor_id']%2 == 0)
			{
				echo "<tr bgcolor= \"gray\">";
			}else
			{
				echo "<tr bgcolor= \"white\">";
			}
			
			echo "<td>" . $row['traktor_id'] . "</td>";
			echo "<td><img src=\"pictures/" . $row['img'] . "\"/></td>";
			echo "<td> " . $row['Top_model'] . "</td>";
			echo "<td><a href=\"modify.php?traktor_id=" . $row['traktor_id'] . "\">Edit</a>\n";
			echo "<td><a href=\"buy_tractor.php?traktor_id=" . $row['traktor_id'] . "\">Buy</a>\n";
			echo "<td><a href=\"del_traktors.php?traktor_id=" . $row['traktor_id'] . "\">Del</a>\n";
			echo "</tr>";
		}
	}else
	{
		echo "<p>No data found</p>";
	}
	
	
	mysqli_close($db_connect);
	echo "</table>"
?>
	
	</div>

</body>
</html>